<?php

declare(strict_types=1);

namespace ImiApp\ApiServer\Api\Controller;

use Phpben\Imi\Auth\AuthManager;
use ImiApp\ImiServer\HttpController;
use Imi\Aop\Annotation\Inject;
use Psr\Http\Message\ResponseInterface;


/**
 * API公共控制器
 */
class CommonController extends HttpController
{
    /**
     * Auth
     * @Inject(AuthManager::class)
     * 
     * @var \Phpben\Imi\Auth\AuthManager
     */
    protected $auth;

    protected $noNeedLogin = "*";

    /**
     * 返回成功
     *
     * @param string $message 消息
     * @param string|array $data 数据
     * @return void
     */
    protected function success($message = null, $data = null)
    {
        return $this->response->success((string)$message, $data)->setHeader('Access-Control-Allow-Origin', "*")->send();   
    }

    /**
     * 返回失败
     *
     * @param string $message 消息
     * @param string|array $data 数据
     * @return void
     */
    protected function error($message = null, $data = null)
    {
        return $this->response->error((string)$message, $data)->setHeader('Access-Control-Allow-Origin', "*")->send();
    }
}
